1. Field of the Invention
The present invention relates to nonvolatile memory, its data updating method, and a card reader equipped with such nonvolatile memory. More specifically, the present invention relates to nonvolatile memory that can protect data within the nonvolatile memory, its data updating method, and a card reader equipped with such nonvolatile memory.
2. Related Background Art
In recent years, memory capacity of flash memory has expanded significantly, and its endurance in terms of how many times it can be rewritten has grown enormously as well. As a result, in addition to its former primary use of storing program codes that are relatively infrequently rewritten, flash memory is also used as nonvolatile memory to store data that are extremely frequently rewritten.
With regard to updating data on flash memory, when updating bit data from “0” to “1”, all data within a block that includes the data to be updated must be deleted (i.e., an operation to logically set the applicable bit data to “1”) due to the properties of flash memory, and pinpointing and deleting only a part of data in a block cannot be done. Accordingly, a data updating processing of flash memory is done according to the following procedure (see FIG. 2).
First, before deleting all data within a block containing the data to be updated, a work area mapped on a volatile memory such as RAM (random access memory) is prepared and the range of data to be deleted is copied and temporarily saved there (step 101). Next, data to be updated is updated in the work area (step 102). In the meantime, data in the applicable block in the flash memory is deleted (step 103). The updated data in the work area is written in the applicable block from which data was deleted in the flash memory (step 104), and data update is completed.
Due to the fact that a delete processing for the flash memory involves deleting all data within a block, the delete processing often requires more time (e.g., in seconds) then other processing. Block sizes of flash memory vary from several dozen bytes to tens of thousands of bytes depending on the product type, and some require up to 15 seconds from the beginning to the end of the delete operation.
However, according to the data update method for flash memory described above, required data content is stored only in RAM from the time the data is deleted from the flash memory and until writing the updated data is completed; if power were to be unexpectedly interrupted during this time, not only would the control of the flash memory be interrupted, but data on RAM, which is a volatile memory, would be lost, which could cause a serious situation in which important data is irretrievably lost.
If such a situation occurs, data written in the flash memory may be corrupted next time the power is turned on, and in the worst case scenario the device that uses the flash memory, such as a card reader, may not operate normally.
In order to solve such problems, circuits to detect that the power is beginning to shut down and backup power sources to supplementally restore power when the power completely shuts down are provided on devices, but these increase the cost of applicable products, and in some cases even force the shape of the applicable products to be modified to accommodate them.